package com.hg.chapter7.websocket;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

@Configuration
@EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

    @Override
    //注册协议节点
    public void registerStompEndpoints(StompEndpointRegistry registry) {
        //增加一个协议节点
        //前端连接地址
        registry.addEndpoint("/endpoint").withSockJS();
    }

    @Override
    //消息代理注册中心
    public void configureMessageBroker(MessageBrokerRegistry config) {
        //配置一个消息代理
        config.enableSimpleBroker("/topic");
    }
}
